<template>
  <div class="background">
    <div class="login-container">
      <h2>用户登录</h2>
      <form @submit.prevent="handleLogin">
        <div class="form-group">
          <label for="username">账号：</label>
          <input
            type="text"
            id="username"
            v-model="username"
            placeholder="请输入账号"
            required
          />
        </div>
        <div class="form-group">
          <label for="password">密码：</label>
          <input
            type="password"
            id="password"
            v-model="password"
            placeholder="请输入密码"
            required
          />
        </div>
        <button type="submit" class="login-button">登录</button>
      </form>
      <div class="social-login">
        <p>其他登录方式：</p>
        <div class="icons">
          <div><img src="/icons/qq-icon.png" alt="QQ" class="icon" /></div>
          <div @click="dingtalkLogin">
            <img src="/icons/dingtalk-icon.png" alt="钉钉" class="icon" />
          </div>
          <div><img src="/icons/wechat-icon.png" alt="微信" class="icon" /></div>
        </div>
      </div>
    </div>
  </div>
  <button @click="dingtalkLogin" class="dingtalk-btn">使用钉钉账号登录</button>
</template>

<script setup>
import axios from 'axios';
import { get } from '@/utils/request';
import { ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';

const token = ref('');
const userid = ref('');
const phone = ref('');
const route = useRoute();
const router = useRouter();

const login = () => {
  console.log('手机号登录', phone.value);
  router.push('/home');
};

const dingtalkLogin = () => {
  get('http://127.0.0.1:8000/user/ding/')
    .then((result) => {
      if (result.data.code == 200) {
        const url = result.data.url;
        window.location.href = url;
      }
    })
    .catch((err) => {
      console.error('请求失败:', err);
    });
};
</script>

<style scoped>
.background {
  background-image: url('https://copyright.bdstatic.com/vcg/creative/7786449bb4a7a0ac784d56f106eef520.jpg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: brightness(0.8); /* 让背景更暗 */
}

.login-container {
  max-width: 400px;
  width: 100%;
  padding: 30px;
  border-radius: 16px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); /* 增强阴影效果 */
  background-color: rgba(255, 255, 255, 0.95); /* 提高透明度 */
  backdrop-filter: blur(15px);
  transition: transform 0.3s, box-shadow 0.3s; /* 增加悬停时动画效果 */
}

.login-container:hover {
  transform: translateY(-10px); /* 悬停时轻微上移 */
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

h2 {
  text-align: center;
  font-size: 24px;
  font-weight: bold;
  color: #333;
  margin-bottom: 20px;
}

.form-group {
  margin-bottom: 20px;
}

label {
  display: block;
  margin-bottom: 8px;
  font-weight: bold;
  color: #555;
}

input {
  width: 100%;
  padding: 12px;
  margin-top: 5px;
  box-sizing: border-box;
  border: 1px solid #ccc;
  border-radius: 8px; /* 圆角更加柔和 */
  outline: none;
  transition: border-color 0.3s;
}

input:focus {
  border-color: #80cbc4; /* 输入框聚焦时颜色变化 */
}

.login-button {
  width: 100%;
  padding: 12px;
  background-color: #43b0c9;
  border: none;
  color: white;
  font-size: 18px;
  cursor: pointer;
  margin-top: 15px;
  border-radius: 8px;
  transition: background-color 0.3s, transform 0.3s;
}

.login-button:hover {
  background-color: #004d40;
  transform: translateY(-3px); /* 按钮悬停时轻微上移 */
}

.social-login {
  margin-top: 30px;
  text-align: center;
  color: #666;
}

.icons {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 10px;
}

.icon {
  width: 40px;
  height: 40px;
  cursor: pointer;
  transition: transform 0.3s;
}

.icon:hover {
  transform: scale(1.3); /* 图标悬停时放大 */
}

.dingtalk-btn {
  background-color: #2ecf73;
  color: white;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.3s;
  margin-top: 20px;
}

.dingtalk-btn:hover {
  background-color: #52cb5c;
}
</style>
